package com.devops.admin.graphql;

import com.devops.admin.po.DOSPodInfoPo;
import com.devops.admin.service.DOSK8sPodService;
import com.devops.admin.service.DOSKubernetesResourceService;
import com.devops.admin.service.DOSReleaseService;
import com.devops.admin.util.Assert;
import com.devops.admin.vo.DOSPodVo;
import com.devops.common.annotation.DOSLog;
import com.devops.constant.DevOpsConstant;
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsMutation;
import com.netflix.graphql.dgs.DgsQuery;
import com.netflix.graphql.dgs.InputArgument;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;


/**
 * @ClassName DOSK8sPodDataFetcher
 * @Description TODO
 * @Author heyabo
 * @Date 2022/8/4 09:36
 * @Version 1.0
 **/
@DgsComponent
public class DOSK8sPodDataFetcher {

    @Autowired
    private DOSK8sPodService dosk8sPodService;

    /**
     * @Author heyabo
     * @Description 删除pod
     * @Date 08:51 2022/4/28
     * @Param [vo]
     * @return boolean
     **/
    @DgsMutation
    @DOSLog(description = "删除pod")
    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    public boolean deletePod(@InputArgument DOSPodVo podVo){
        Assert.isTrue(podVo != null ,"参数不能为空");
        return dosk8sPodService.deleteK8sClusterPod(podVo.getPodName(), podVo.getId(),podVo.getType());
    }

    /**
     * @Author heyabo
     * @Description 获取pod详情
     * @Date 09:13 2022/5/20
     * @Param [releaseId, podName]
     * @return com.devops.admin.po.DOSPodInfoPo
     **/
    @DgsQuery
    @DOSLog(description = "获取pod详情")
    @RequiresPermissions(DevOpsConstant.RoleCode.LOGIN_USER)
    public DOSPodInfoPo getPodInfo(@InputArgument DOSPodVo podVo){

        return dosk8sPodService.queryPodInfo(podVo.getId(),podVo.getPodName(),podVo.getType());
    }
}
